package com.hssy.wululuaplan.controller;

import com.hssy.wululuaplan.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "通知")
@RestController
@RequestMapping("/notice")
public class NoticeController {
    private static final List<String> noticeCacheList = new ArrayList<>();

    @ApiOperation("发送通知")
    @PostMapping("/send")
    public Result<String> send(String message) {
        noticeCacheList.add(message);

        return Result.success("发送成功");
    }


    @ApiOperation("看通知")
    @GetMapping("/watch")
    public Result<String> send() {
        if (noticeCacheList.size() > 0) {
            String message = noticeCacheList.get(noticeCacheList.size() - 1);
            noticeCacheList.remove(noticeCacheList.size() - 1);
            return Result.success(message);
        }
        return Result.success("暂无通知");
    }
}
